package controller

import (
	"context"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"net/http"
	"strconv"
	"user_bff/pkg"
	"user_bff/user_proto"
)

func DetailBook(c *gin.Context) {
	bookId := c.Query("book_id")
	bookIdInt, _ := strconv.Atoi(bookId)
	if bookIdInt == 0 {
		c.JSON(http.StatusNotFound, gin.H{
			"code": -1,
			"msg":  "参数不能为空",
			"data": nil,
		})
		return
	}
	comment := pkg.Comment()
	name, err := comment.GetBooksByName(context.Background(), &user_proto.GetBooksByNameRequest{Id: int64(bookIdInt)})
	if err != nil {
		c.JSON(http.StatusNotFound, gin.H{
			"code": -1,
			"msg":  "查询漫画失败",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 0,
		"msg":  "查询成功",
		"data": name,
	})
	zap.S().Info(name)
}
